package com.base.myproject.client.HR.holiday;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.BaseOpenJSP;
import com.base.myproject.client.ui.celleditor.BaseCheckGroup;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
 * 假期报表
 * @author cxghiu410@gmail.com
 *
 */
public class VacationReport extends BaseJDBCPanel{
	private BaseOpenJSP jspPanel = null;
	private String jspFile = null;
	private DateField dfBegin = null;
	private DateField dfEnd = null;
	private Button btnQuery = null;
	
	public VacationReport(){
		init();
	}
	
	public void init(){
		initWidget();
	}
	
	public void complete() {
		super.complete();
		print.addListener(Events.Select, getListener());
		getToolbarll().add(print);
	}
	
	public void initWidget(){
		jspFile = "./hr_Jsp/rptVacationReport.jsp";
		jspPanel = new BaseOpenJSP(jspFile);
		jspPanel.setBorders(false);
		Tools.setResize(jspPanel, 0.99, 0.9);
		
		HorizontalPanel hp = new HorizontalPanel();
		hp.setSpacing(3);
		dfBegin = new DateField();
		dfBegin.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		dfEnd = new DateField();
		dfEnd.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		btnQuery = new Button("查询");
		btnQuery.addListener(Events.OnClick, getListener());
		
		
		hp.add(new Label("从:"));
		hp.add(dfBegin);
		dfBegin.setWidth(100);
		hp.add(new Label("到:"));
		dfEnd.setWidth(100);
		hp.add(dfEnd);
		hp.add(btnQuery);
		
		VerticalPanel vp = new VerticalPanel();
		vp.setSpacing(3);
		vp.add(hp);
		vp.add(jspPanel);
		add(vp);
		this.layout();
	}
	
	int sync = 0;                                                      
	Listener<BaseEvent> defaultlistener;                               
                                                                     
	public Listener<BaseEvent> getListener() {                                
		if(defaultlistener!=null)                                        
		{                                                                
			return defaultlistener;                                        
		}                                                                
                                                                     
		defaultlistener = new Listener<BaseEvent>() {                    
			public void handleEvent(BaseEvent be) {                        
				sync++;                                                    
				try {                                                      
					if (sync == 1) {                                   
						if (be.getType() == Events.Select) { 
							jspPanel.Print();
						}else if(be.getType() == Events.OnBlur){
							
						}else if(be.getType() == Events.OnClick){
							if(be.getSource().equals(btnQuery)){
								String beginTime = dfBegin.getRawValue();
								String endTime = dfEnd.getRawValue();
								if(beginTime.equals("") || endTime.equals("")){
									MessageBox.alert("提示", "查询信息填写不完整", null);
								}else{
									jspFile += "?beginTime=" + beginTime + "&endTime=" + endTime;
									jspPanel.getFrame().setUrl(jspFile);
									jspFile = "./hr_Jsp/rptVacationReport.jsp";
									
								}
							}
						}                                          
					}                                                  
				} finally {                                                
					sync--;                                            
				}                                                          
			}                                                              
		};                                                               
		return defaultlistener;                                          
	}
}
